package com.cl.mypureframe.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.cl.mypureframe.R;
import com.cl.mypureframe.conn.Conn;
import com.cl.mypureframe.conn.RetrofitUtil;
import com.cl.mypureframe.model.NongjiMod;
import com.cl.mypureframe.model.ResBaseMod;
import com.cl.mypureframe.util.Log;

import java.util.List;

import retrofit2.Call;

/**
 * @Class: DownloadActivity
 * @Description:
 * @Author: ChenLei
 * @Date: 2020/12/11---16:01
 */
public class DownloadActivity extends BaseActivity {
    private String url = "http://p.gdown.baidu.com/2c94946f0e26ae462034226fde89692a269f6bdf2aa6e9c8767d772124c9f7c7d260e6931fef78f570c881e16b38ef5c2078652c803b022fe844fb87d68c894ddbef8a9694a05f1e0ff373231ca712808c4440578d04145cdba6bc15f63a58840b47586cd429087098129921afed1197f1295b0f2cf49ff9250a04c0d4ef1ae92fdb5712c98e32f6be819bd5d37ee48e968923ef76a8cc7fb9742033e72b07c84dd4e14dc8d7931011e1242b1a867296948cf07eaea2a39a3dfd57541fe83eade2e5b448b9ba397e0a84fc90bc2405b969c9634da0803afc6b0464e4a7e333bb0c7072bd418e99312b5457043c33f156a13660aba0be6f15";//较小的apk文件
    private String url2 = "http://mhhy.dl.gxpan.cn/apk/ml/MBGYD092101/Gardenscapes-ledou-MBGYD092101.apk";// 梦幻花园游戏包体较大，可以很好的查看下载效果

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initContenViewAndBack(R.layout.activity_download, R.string.downactivity);

    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onButtonClick(View view) {
        switch (view.getId()) {
            case R.id.btn_1:// 浏览器下载
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
                break;
            case R.id.btn_2:// downloadmanager
                testConnAction();
                break;
        }
    }

    /**
     * http://202.118.163.212:8057/apm/resource/machineList.do?userId=112615&cardNum=232321196809023312
     */
    private void testConnAction() {
        RetrofitUtil<ResBaseMod<List<NongjiMod>>> retrofitUtil = new RetrofitUtil<>();
        Call<ResBaseMod<List<NongjiMod>>> call = retrofitUtil.getRetrofit().getMachineListInfo("112615", "232321196809023312");
        retrofitUtil.connAction(call, this, response -> {
            ResBaseMod<List<NongjiMod>> resBaseMod = response.body();
            if (resBaseMod.getCode() == Conn.CODE_SUCCESS) {
                List<NongjiMod> nongjiModList = resBaseMod.getContent();
                Log.i(TAG, "nongjiModList", nongjiModList.toString());
            } else {

            }

        });

    }
}
